

PREVIEWER = {}

AccessorFunc( PREVIEWER, "PLY", "ENT" )
AccessorFunc( PREVIEWER, "PCamPos", "CamPos" )
AccessorFunc( PREVIEWER, "PLookAt", "LookAt" )


function PREVIEWER:Init()
	print( "PANEL INITIATED" )
	local Frame = vgui.Create( "DFrame" )
		Frame:SetSize( ScrW(), ScrH() )
		function Frame:Paint()
			surface.SetDrawColor( Color( 100, 100, 100, 255 ) )
			surface.DrawRect( 0, 0, ScrW(), ScrH() )
			
			surface.SetDrawColor( Color( 200, 200, 200, 255 ) )
			surface.DrawRect( Frame:GetWide() * 0.02, Frame:GetTall() * 0.02, Frame:GetWide() * 0.96, Frame:GetTall() * 0.96 )
		end	
	self.PLY = nil
	
	if !ClientsideModel then return
	else
	
		self.PLY = ClientsideModel( LocalPlayer():GetModel(), RENDERGROUP_OPAQUE )
		self.PLY:SetNoDraw( true )
	end
	
	self:SetCamPos( Vector( 50, 50, 50 ) )
	self:SetLookAt( Vector( 0, 0, 40 ) )
end

function PREVIEWER:Paint()
	if !self.PLY:IsValid() then return end
	
	cam.Start3D( self.PCamPos, (self.PLookAt-self.PCamPos):Angle() )
	cam.IgnoreZ( true )
	
	render.SuppressEngineLighting( true )
	render.SetLightingOrigin( self.PLY:GetPos() + Vector(0,0,60) )
	
	
	self.PLY:DrawModel()
	
	render.SuppressEngineLighting( false )
	cam.IgnoreZ( false )
	cam.End3D()

end

vgui.Register( "ItemPreview", PREVIEWER, "DPanel" )